//
//  SevericeTerritoryViewController.m
//  MemberProject
//
//  Created by mac on 15/4/20.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "SevericeTerritoryViewController.h"

@interface SevericeTerritoryViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)UITableView *tableView;
@property(strong,nonatomic)NSArray *data;
@end

@implementation SevericeTerritoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *arr= @[@"扶贫济困",@"助老助残",@"社区服务",@"生态建设",@"大型活动",@"抢险救灾",@"网络文明",@"社会管理",@"文化建设",@"西部开发",@"海外服务"];
    NSMutableArray *arrM=[NSMutableArray array];
    for(int i=0;i<arr.count;i++){
//        [arrM addObject:@{@"name":arr[i],@"isSelected":[NSNumber numberWithBool:NO]}];
        [arrM addObject:[NSMutableDictionary dictionaryWithDictionary:@{@"name":arr[i],@"isSelected":[NSNumber numberWithBool:NO]}]];
    }
    self.data=arrM;
    UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 30*self.data.count) style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    self.tableView=tableView;
    tableView.delegate=self;
    tableView.dataSource=self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CellIdentifier"];
    
}

#pragma mark - tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier=@"CellIdentifier";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text=self.data[indexPath.row][@"name"];
    BOOL isSelected=[self.data[indexPath.row][@"isSelected"] boolValue];
    if(isSelected==YES){
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }else{
        cell.accessoryType=UITableViewCellAccessoryNone;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSMutableDictionary *dicM=self.data[indexPath.row];
    [dicM setValue:[NSNumber numberWithBool:![dicM[@"isSelected"] boolValue]] forKey:@"isSelected"];
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end
